import { list, add, edit, remove } from './service'

const Model = {
  namespace: 'PAGE_NAME',
  state: {
    dataList: [],
  },
  effects: {
    *list({}, { call, put }) {
      const response = yield call(list, { pageNum: 1, pageSize: 1000 })
      yield put({
        type: 'setDataList',
        payload: response.data.list,
      })
    },

    *add({ payload, callback }, { call }) {
      console.log(payload)
      const resp = yield call(add, payload)
      if (callback) {
        callback(resp)
      }
    },
    *edit({ payload, callback }, { call }) {
      console.log(payload)
      const resp = yield call(edit, payload)
      if (callback) {
        callback(resp)
      }
    },

    *remove({ payload, callback }, { call }) {
      console.log(payload)
      const resp = yield call(remove, payload)
      if (callback) {
        callback(resp)
      }
    },
  },
  reducers: {
    setDataList(state, { payload }) {
      return { ...state, dataList: payload }
    },
  },
}
export default Model
